package com.ququ.syb.entrance.controller;

import com.ququ.syb.entrance.po.RequestData;
import com.ququ.syb.entrance.service.PayChannelService;
import com.ququ.syb.entrance.vo.SybResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 支付通道模块
 *
 * @author macro
 * @date 2019-08-26
 *
 */
@RestController
@RequestMapping("/syb/controller")
public class ChannelController {
    @Autowired
    private PayChannelService payChannelService;



    /**
     * /p1501 查询可用支付通道
     *
     * @param header.terminalno 终端号，随便填|必填
     * @param header.requesttype 请求类型，默认为1|必填
     * @param header.operationid 请求id|必填
     * @param header.appcode 应用代码|必填
     * @param header.terminaltype 默认填1|必填
     * @param header.timestamp 时间戳|必填
     * @param encryptiontype 加密方式 1-AES加密 3-明文，这里填1|必填
     * @param accountid 生意宝账户|必填
     * @param data 业务数据请求部分，传AES加密后的空或{}即可|必填
     * @param sign 签名|必填
     * @return 本账户所有开通可用的支付通道列表
     * @respbody {"status":1,"msg":"成功","data":{"accountid":"100000000064","result":"y8raOUpv2DtVR0XH4mk7OtDJlY9SlRMpRk+0HHRb0FSA5zpXXLXtbWnFkPr/pWlra441QAkJrV9L9gatLILYkjwKsoQe0Z3h4WwKQWl0EWGh1tC9lvE12tHvw2/Th1peEkrfmdbiNOwb3VqDiF67A2W6DeIt+yYqF4hEhXcKSkspaNDbDLv33Kt5XEux0BdUpsltbT7ILmPfndp/zbO8ehvHJCi2kv0P98LnE/sKjDB2PRcnqhmiXC5+GlvLYPPosHLot8nb+WQJug3dib3X01Zo0BdTwQi0US6yZS3bk6YkPegQ4OZkXB6DN4U0KuGLsPATBNab3fvrl1Cfm1DaOOcLK1J/lomLyFoE9NM2wjJkPhcU+pCTvi7zYeW0LT31TOP8nyRzI0pvNJi9pjvVWsx5NnOdlkZHZFlDX4Xm68s/Poqzcct77tDfp3cx3xTKkfG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9o0ATe7mntzoIYoAmAVJbnnC8+DN39HvV8UABAG9W12zDkVyZBG9digt4LpLgGWC8bqVQlZ7wXHPVRxd1EwKM/6xDiRnds="},"page":{"count":1,"index":1,"size":10,"total":1},"sign":"491a21759216c310517a72fb3e353896"}
     * @resp status 状态值，1-成功 其他值-失败|int
     * @resp msg 错误信息|string
     * @resp data.accountid 生意宝账号id|string
     * @resp data.result 明文 [{"channeltype":1,"companyname":"中茂恒润","customercommissionrate":0.0030,"maxpayamount":20000,"minpayamount":1,"needconfirm":0,"needcvv":1,"paychannelid":"401","paychannelname":"中茂快捷T0(伪直清)","webpay":0,"withdrawtype":1},{"channeltype":2,"companyname":"中茂恒润","customercommissionrate":0.0046,"maxpayamount":20000,"minpayamount":0.01,"needconfirm":0,"needcvv":0,"paychannelid":"417","paychannelname":"中茂云闪付APP(伪直清)","webpay":0,"withdrawtype":1},{"channeltype":1,"companyname":"中茂恒润","customercommissionrate":0.0055,"maxpayamount":50000,"minpayamount":2.01,"needconfirm":1,"needcvv":1,"paychannelid":"418","paychannelname":"中茂新快捷T0(动态商户)","webpay":0,"withdrawtype":1},{"channeltype":1,"companyname":"中茂恒润","customercommissionrate":0.0035,"maxpayamount":1000,"minpayamount":2.01,"needconfirm":1,"needcvv":1,"paychannelid":"419","paychannelname":"中茂新快捷T0(商圈小额)","webpay":0,"withdrawtype":1},{"channeltype":2,"companyname":"中茂恒润","customercommissionrate":0.00,"maxpayamount":20000,"minpayamount":0.01,"needconfirm":0,"needcvv":0,"paychannelid":"423","paychannelname":"中茂云闪付APP(借记卡)","webpay":0,"withdrawtype":1}]|string
     * @resp data.result.channeltype 支付通道类型 1-快捷 2-网关 3-扫码|int
     * @resp data.result.companyname 支付公司名称|string
     * @resp data.result.customercommissionrate 通道费率|double
     * @resp data.result.maxpayamount 单笔最大支付金额，单位为元|int
     * @resp data.result.minpayamount 最小支付金额，单位为分|int
     * @resp data.result.needconfirm 是否需要短信确认 1-需要 0-不需要|int
     * @resp data.result.needcvv 是否需要cvv有效期 1-需要 0-不需要|int
     * @resp data.result.paychannelid 通道号|string
     * @resp data.result.paychannelname 通道名称|string
     * @resp data.result.webpay 是否WAP模式 1-WAP 0-API|int
     * @resp data.result.withdrawtype 提现类型|int
     * @resp page 分页信息，可忽略|object
     */
    @RequestMapping("/p1501")
    public SybResult listMyPayChannels(@RequestHeader String appcode,
                                    @RequestHeader(required = false) String timeStamp,
                                    @RequestHeader(required = false) String operationid,
                                    @RequestHeader(required = false) String operationname,
                                    @RequestParam String accountid,
                                    @RequestParam String data,
                                    @RequestParam String sign,
                                    @RequestParam Integer encryptiontype){
        RequestData<String> requestData = new RequestData<>(appcode,accountid,operationid,operationname,data,sign,encryptiontype);
        return payChannelService.listMyPayChannels(requestData);
    }


    /**
     * /p1503 查询指定支付通道详情
     *
     * @param header.terminalno 终端号，随便填|必填
     * @param header.requesttype 请求类型，默认为1|必填
     * @param header.operationid 请求id|必填
     * @param header.appcode 应用代码|必填
     * @param header.terminaltype 默认填1|必填
     * @param header.timestamp 时间戳|必填
     * @param encryptiontype 加密方式 1-AES加密 3-明文，这里填1|必填
     * @param accountid 生意宝账户|必填
     * @param data 业务数据请求部分，JSON格式，AES加密|必填
     * @param data.paychannelid 支付通道号|必填
     * @param sign 签名|必填
     * @return 当前支付通道详细信息
     * @respbody {"status":1,"msg":"成功","data":{"accountid":"100000000064","result":"Q4+b/oGWRzsbOFU6Lu6Q9+cLK1J/lomLyFoE9NM2wjJkPhcU+pCTvi7zYeW0LT31TOP8nyRzI0pvNJi9pjvVWs07Vl7H5gecARoemrZ6w4A/Poqzcct77tDfp3cx3xTKkfGqDzh68UyiH3dsa32JJz//wbJ8j7ZYpjgJ7qGgQa9F+y8K/MfvWooaxp0HPMWSZYM9mO/KsIA312TWHBzGX4v4ap6Jk/DuIVItiuvn81gyEb0ElpU79gPcVmb2sWOF3UGA7ksycDbft1E7kgDKXGSC0vcVa/E97miadcRrSbV5nz4zeMEMzHQ0gQ2jhe73"},"page":{"count":1,"index":1,"size":10,"total":1},"sign":"938b71581c80f095df336a286d2e9baa"}
     * @resp status 状态值，1-成功 其他值-失败|int
     * @resp msg 错误信息|string
     * @resp data.accountid 生意宝账号id|string
     * @resp data.result 明文 {"channeltype":1,"companyname":"中茂恒润","customercommissionrate":0.0030,"maxpayamount":20000,"minpayamount":1,"needconfirm":0,"needcvv":1,"paychannelid":"401","paychannelname":"中茂快捷T0(伪直清)","webpay":0,"withdrawtype":1}|string
     * @resp data.result.channeltype 支付通道类型 1-快捷 2-网关 3-扫码|int
     * @resp data.result.companyname 支付公司名称|string
     * @resp data.result.customercommissionrate 通道费率|double
     * @resp data.result.maxpayamount 单笔最大支付金额，单位为元|int
     * @resp data.result.minpayamount 最小支付金额，单位为分|int
     * @resp data.result.needconfirm 是否需要短信确认 1-需要 0-不需要|int
     * @resp data.result.needcvv 是否需要cvv有效期 1-需要 0-不需要|int
     * @resp data.result.paychannelid 通道号|string
     * @resp data.result.paychannelname 通道名称|string
     * @resp data.result.webpay 是否WAP模式 1-WAP 0-API|int
     * @resp data.result.withdrawtype 提现类型|int
     * @resp page 分页信息，可忽略|object
     */
    @RequestMapping("/p1503")
    public SybResult getMyPayChannel(@RequestHeader String appcode,
                                               @RequestHeader(required = false) String timeStamp,
                                               @RequestHeader(required = false) String operationid,
                                               @RequestHeader(required = false) String operationname,
                                               @RequestParam String accountid,
                                               @RequestParam String data,
                                               @RequestParam String sign,
                                               @RequestParam Integer encryptiontype){
        RequestData<String> requestData = new RequestData<>(appcode,accountid,operationid,operationname,data,sign,encryptiontype);
        return payChannelService.getPayChannel(requestData);
    }

}
